package com.yuanlrc.base.entity.admin;

import com.yuanlrc.base.annotion.ValidateEntity;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * 违规管理实体类
 */
@Entity
@Table(name="ylrc_violation")
@EntityListeners(AuditingEntityListener.class)
public class Violation extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @Column(name="id",nullable=false,length=11)
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Id
    private Long id;//唯一id

    @ManyToOne
    @JoinColumn(name = "student_id")
    private Student student;//违规列表 学生类对象

    @ManyToOne
    @JoinColumn(name = "book_id")
    private Book book;//违规列表 图书类对象

    @ManyToOne
    @JoinColumn(name = "borrow_id")
    private Borrow borrow; //借阅记录


    @Column(name = "book_name",nullable = true)
    private String bookName;  //图书名称

    @Override
    public String toString() {
        return "Violation{" +
                "id=" + id +
                ", student=" + student +
                ", book=" + book +
                ", borrow=" + borrow +
                ", bookName='" + bookName + '\'' +
                ", reasonsForViolation='" + reasonsForViolation + '\'' +
                '}';
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }


    @ValidateEntity(required=true,requiredLeng=true,minLength=4,maxLength=18,errorRequiredMsg="违规原因不能为空!",errorMinLengthMsg="违规长度需大于4!",errorMaxLengthMsg="违规长度不能大于18!")
    @Column(name = "reasons_for_violation",nullable = false,length = 255)
    private String reasonsForViolation;//违规原因

    public Borrow getBorrow() {
        return borrow;
    }

    public void setBorrow(Borrow borrow) {
        this.borrow = borrow;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public String getReasonsForViolation() {
        return reasonsForViolation;
    }

    public void setReasonsForViolation(String reasonsForViolation) {
        this.reasonsForViolation = reasonsForViolation;
    }


}
